package com.wll.android.drawp1;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

public class Practice7DrawRoundRectView extends View {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    RectF rectF = new RectF(340, 120, 740, 320);

    public Practice7DrawRoundRectView(Context context) {
        super(context);
    }

    public Practice7DrawRoundRectView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Practice7DrawRoundRectView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

//        练习内容：使用 canvas.drawRoundRect() 方法画圆角矩形
        // 圆角的横向半径和纵向半径
        int rx = 40, ry = 40;
//        paint.setStyle(Paint.Style.STROKE);
//        canvas.drawRoundRect(340, 120, 740, 320, 40, 40, paint1);
//        canvas.drawRoundRect(340, 420, 740, 620, 40, 40, paint2);
        canvas.drawRoundRect(rectF, rx, ry, paint);

        rectF.set(340, 420, 740, 620);
        canvas.drawRoundRect(rectF, rx, ry, paint);
    }
}
